package com.business.dynamic.controller;


import com.business.redis.constant.RedisKeyConstant;
import com.business.redis.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.business.common.dto.R;
import com.business.dynamic.entity.DynamicType;
import com.business.dynamic.utils.PageFactory;
import com.business.dynamic.service.DynamicTypeService;

import java.util.List;

/**
 * : 后端controller类
 *
 * @author chenjiehong
 * @date 2020-03-08 23:38:51
 * @since 1.0
 */
@RestController
@RequestMapping(value = "/dynamicType")
public class DynamicTypeController {


    @Autowired
    private DynamicTypeService dynamicTypeServiceImpl;


    /**
     * 查询字典项表
     *
     * @param state
     * @date 2019-04-28 15:03:17
     */
    @GetMapping("/queryList")
    @ResponseBody
    public R<List<DynamicType>> query(@RequestParam("state") Integer state) {
        String redisKey = String.format(RedisKeyConstant.DICTIONARY_TYPE_QUERY_LIST, state);
        if (!RedisUtil.hasKey(redisKey)) {
            List<DynamicType> r = dynamicTypeServiceImpl.queryList(state);
            RedisUtil.setValue(redisKey, r);
            return R.success(r);
        } else {
            return R.success(RedisUtil.getArray(redisKey, DynamicType.class));
        }
    }

}